export const ReserveStatusEnum = [
  { code: 0, label: '全部', status: 'Default' },
  { code: 1, label: '已预约', status: 'Success' },
  { code: 2, label: '预约完成', status: 'Default' },
  { code: 3, label: '手动取消', status: 'Warning' },
  { code: 4, label: '超时取消', status: 'Error' },
  { code: 5, label: '已入场', status: 'Processing' },
  { code: 7, label: '停车中', status: 'Processing' },
  { code: 10, label: '超时取消', status: 'Warning' },
  { code: 11, label: '已取消', status: 'Warning' },
];

export const ReserveStatusParse = {
  parse: (num: number) => {
    const obj = ReserveStatusEnum.find((item) => item.code === num) || ReserveStatusEnum[0];
    if (num < 0) {
      obj.label = '未知';
    }
    return { ...obj, val: num };
  },
};

export const ParkingReservationStatus = {
  valueEnumMap: () => {
    const map = {};
    ReserveStatusEnum.forEach((item) => {
      map[item.code] = {
        text: item.label,
        status: item.status,
      };
    });
    return map;
  },
  parse: (num: number) => {
    const obj = ReserveStatusEnum.find((item) => item.code === num) || ReserveStatusEnum[0];
    if (num < 0) {
      obj.label = '未知';
    }
    return { ...obj, val: num };
  },
};

export interface OptionsEnum {
  code: number;
  label: string;
  status: string;
}

export const ReservationOrderStatusEnum = [
  { code: 0, label: '全部', status: 'Default' },
  { code: 1, label: '未支付', status: 'default' },
  { code: 2, label: '待补缴', status: 'error' },
  { code: 3, label: '已完成', status: 'success' },
  { code: 4, label: '进行中', status: 'processing' },
  { code: 5, label: '已取消', status: 'warning' },
  { code: -1, label: '未知', status: 'Default' },
];

export const ReservationOrderStatus = {
  valueEnumMap: () => {
    const map = {};
    ReservationOrderStatusEnum.forEach((item) => {
      if (item.code >= 0) {
        map[item.code] = {
          text: item.label,
          status: item.status,
        };
      }
    });
    return map;
  },
  parse: (num: number) => {
    const obj =
      ReservationOrderStatusEnum.find((item) => item.code === num) || ReserveStatusEnum[0];
    if (num < 0) {
      obj.label = '未知';
    }
    return { ...obj, val: num };
  },
};

export const ReservationPaymentStatusEnum = [
  { code: 0, label: '全部', status: 'Default' },
  { code: 1, label: '待支付', status: 'processing' },
  { code: 2, label: '已支付', status: 'success' },
  { code: 4, label: '已退款', status: 'warning' },
  { code: 5, label: '已关闭', status: 'default' },
  { code: 6, label: '退款失败', status: 'error' },
  { code: -1, label: '未知', status: 'error' },
];

export const CommonSelectionStatus = {
  valueEnumMap: (options: OptionsEnum[]) => {
    const map = {};

    options.forEach((item) => {
      if (item.code >= 0) {
        map[item.code] = {
          text: item.label,
          status: item.status,
        };
      }
    });
    return map;
  },

  parse: (num: number, options: OptionsEnum[]) => {
    const obj = options.find((item) => item.code === num) || ReserveStatusEnum[0];
    if (num < 0) {
      obj.label = '未知';
    }
    return { ...obj, val: num };
  },
};
